<template>
   <HomePanel ref="target" title="人气推荐" subTitle="人气爆款 不容错过">
        <template #right>
            <XtxMore />
        </template>
       <template #default>
      <!-- <ul ref="pannel" class="goods-list">
        <li v-for="item in hotList" :key="item.id">
          <RouterLink to="/">
            <img :src="item.picture" alt="" />
            <p class="name">{{item.title}}</p>
          <p class="desc">{{item.alt}}</p>
          </RouterLink>
        </li>
      </ul> -->
      <!-- 商品组件 -->
    <HomeList :list="hotList"/>
    </template>
    </HomePanel>
</template>

<script>
import { ref } from 'vue'
import { findHot } from '@/api/home'
import HomePanel from './home-panel.vue'
// 导入商品组件
import HomeList from './home-list.vue'
import { useObserver } from '@/hooks'

export default {
  name: 'HomeRecom',
  components: {
    HomePanel,
    HomeList
  },
  setup () {
    // 定义商品数据
    const hotList = ref([])
    // 获取商品列表数据
    const getHotList = async () => {
      const { result } = await findHot()
      //   console.log(result)
      hotList.value = result
    }
    // onMounted(() => {
    //   getHotList()
    // })

    // 调用监控元素进入可视区域函数
    const { target } = useObserver(getHotList)

    return { hotList, target }
  }
}
</script>

<style lang="less" scoped>

</style>
